package com.example.loki.griddemo;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

/**
 * Created by ZR112916 on 2018/1/22.
 */

public class MyAdapter extends RecyclerView.Adapter<MyHolder> {

    ArrayList<MyButton> mList;
    Context mContext;

    public MyAdapter(Context context, ArrayList<MyButton> myButtons) {
        mContext = context;
        mList = myButtons;
    }


    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_my_button, parent, false);
        MyHolder holder = new MyHolder(view,mContext);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        holder.mTvText.setText(mList.get(position).text);
        //TODO 其他的参数也在这里设置，比如图片，还有左上，右下的小图显示不显示的逻辑等
        holder.mIvLeftTop.setVisibility(mList.get(position).isShowLT ? View.VISIBLE : View.GONE);
        holder.mIvRightBottom.setVisibility(mList.get(position).isShowRB ? View.VISIBLE : View.GONE);
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

}
